package com.one.common.view.pagestate.statepage;

import android.view.View;
import android.widget.FrameLayout;

import com.one.common.R;
import com.one.common.presenter.BasePresenter;
import com.one.common.view.base.BaseActivity;


/**
 * creator: zhulunjun
 * time:    2018/3/8
 * describe: 页面状态抽象
 * 这里使用ViewStub 来切换不同的状态，懒加载，节约资源
 * ViewStub 直接继承自View，是一种不可见，0大小的可以在运行的时候再加载的View
 */

public abstract class BaseStateActivity<T extends BasePresenter> extends BaseActivity<T> implements StatePageInterface {

    FrameLayout flContent;
    View viewError;
    View viewEmpty;
    View viewLoading;
    public View successView;
    private StatePageHandle mStatePageHandle;

    @Override
    public boolean haveRootView() {
        return true;
    }

    @Override
    public int getSecondLayoutResId() {
        return R.layout.page_state;
    }

    @Override
    public void initView() {
        flContent = (FrameLayout) findViewById(R.id.fl_content);
        viewError = findViewById(R.id.view_error);
        viewEmpty = findViewById(R.id.view_empty);
        viewLoading = findViewById(R.id.view_loading);
        mStatePageHandle = new StatePageHandle(getContext(), this, this);
        mStatePageHandle.initView(flContent, viewError, viewEmpty, viewLoading);
        successView = mStatePageHandle.successView;
    }

    @Override
    public void success() {
        mStatePageHandle.success();
    }

    @Override
    public void empty() {
        mStatePageHandle.empty();
    }

    @Override
    public void setEmptyRes(int emptyRes) {
        mStatePageHandle.setEmptyRes(emptyRes);
    }

    @Override
    public void setEmptyStr(String emptyStr) {
        mStatePageHandle.setEmptyStr(emptyStr);
    }

    @Override
    public void error() {
        mStatePageHandle.error();
    }

    @Override
    public void loading() {
        mStatePageHandle.loading();
    }

    @Override
    public void empty(String emptyStr) {
        mStatePageHandle.empty(emptyStr);
    }

    @Override
    public void empty(int imageRes, String emptyStr) {
        mStatePageHandle.empty(imageRes, emptyStr);
    }

    @Override
    public void error(String errorStr) {
        mStatePageHandle.error(errorStr);
    }

    @Override
    public void error(int imageRes, String errorStr) {
        mStatePageHandle.error(imageRes, errorStr);
    }

    @Override
    public void setEmptyView(View view) {
        mStatePageHandle.setEmptyView(view);
    }

    @Override
    public void setErrorView(View view) {
        mStatePageHandle.setErrorView(view);
    }

    @Override
    public void setLoadingView(View view) {
        mStatePageHandle.setLoadingView(view);
    }

    @Override
    public void onEmptyClick() {
        mStatePageHandle.onEmptyClick();
    }

    @Override
    public void onErrorClick() {
        mStatePageHandle.onErrorClick();
    }

    @Override
    public boolean onError() {
        return false;
    }

    @Override
    public boolean onEmpty() {
        return false;
    }
}
